﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ComicIsland.Common;
using ComicIsland.Common.Entities.LocalJson;
using ComicIsland.Common.StorageHelper;

/**
 * 创建时间：2015/1/14 10:50:41
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace ComicIsland.App.CIHelper
{
    public class LocalAppConfigInfoHelper
    {
        public string FilePath { get; private set; }
        public LocalAppConfigInfoHelper()
        {
            this.FilePath = "LocalAppConfigInfo";
        }

        public bool AddOrUpdate(LocalAppConfigInfo appConfigInfo)
        {
            bool result = false;
            try
            {
                string json = JSONHelper.Serialize<LocalAppConfigInfo>(appConfigInfo);
                if (!string.IsNullOrWhiteSpace(json))
                {
                    IsolatedStorageHelper.Instance.WriteText(json, this.FilePath, true);
                    result = true;
                }
            }
            catch { }
            return result;
        }


        public LocalAppConfigInfo Get()
        {
            LocalAppConfigInfo result = null;
            try
            {
                if (IsolatedStorageHelper.Instance.FileExists(this.FilePath))
                {
                    string json = IsolatedStorageHelper.Instance.ReadText(this.FilePath);
                    if (!string.IsNullOrWhiteSpace(json))
                    {
                        result = JSONHelper.Deserialize<LocalAppConfigInfo>(json);
                    }
                }
            }
            catch { }
            return result;
        }
    }
}
